package com.example.umbrella.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.umbrella.R;
import com.google.android.material.snackbar.Snackbar;

public class UIHelper {
    private Dialog loadingDialog;
    private Context context;

    public UIHelper(Context context) {
        this.context = context;
        initLoadingDialog();
    }

    private void initLoadingDialog() {
        loadingDialog = new Dialog(context, R.style.TransparentDialog);
        View view = LayoutInflater.from(context).inflate(R.layout.custom_loading_dialog, null);
        loadingDialog.setContentView(view);
        loadingDialog.setCancelable(false);
    }

    public void showLoading(String message) {
        if (loadingDialog != null) {
            TextView messageView = loadingDialog.findViewById(R.id.loading_message);
            messageView.setText(message);
            loadingDialog.show();
        }
    }

    public void hideLoading() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
        }
    }

    public void showError(View anchorView, String message, String actionText, View.OnClickListener action) {
        Snackbar snackbar = Snackbar.make(anchorView, message, Snackbar.LENGTH_LONG);
        if (action != null && actionText != null) {
            snackbar.setAction(actionText, action);
        }
        snackbar.setBackgroundTint(context.getResources().getColor(R.color.error_background, null));
        snackbar.setTextColor(context.getResources().getColor(R.color.white, null));
        snackbar.show();
    }

    public void showSuccess(String message) {
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }
} 